package cn.iocoder.yudao.module.product.favorite.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.favorite.service.AppProductFavoriteService;
import cn.iocoder.yudao.module.product.favorite.vo.AppProductFavoriteVO;
import cn.iocoder.yudao.module.product.spu.vo.AppProductSpuPrimaryReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 APP - 产品收藏")
@RestController
@RequestMapping("/product/favorite")
public class AppProductFavoriteController {
    @Resource
    private AppProductFavoriteService productFavoriteService;

    @PostMapping("/toggle")
    @Operation(summary = "收藏/取消收藏")
    public CommonResult<Boolean> toggle(@Valid @RequestBody AppProductSpuPrimaryReqVO reqVO) {
        return success(productFavoriteService.toggle(reqVO.getSpuId(), getLoginUserId()));
    }

    @GetMapping("/page")
    @Operation(summary = "获得收藏分页")
    public CommonResult<PageResult<AppProductFavoriteVO>> page(@Valid PageParam reqVO) {
        return success(productFavoriteService.getPage(reqVO.getPageNo(), reqVO.getPageSize(), getLoginUserId()));
    }

}
